// pages/help/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeData: {
      'hours': '',
      'minutes': '',
      'seconds': '',
      'isData': true,
      'percent': '',
    },
    userList: [
      {
        "avatar": '../images/guangguang.jpg',
        'nickName': '张三',
        'percent': '2%'
      },
      {
        "avatar": 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83epia5uwicw5nw1VhX9XCFHg0rRd6Bcy9VGczNDwyYEdTOL1C5fbFEu64PKrccdVNVHvCXx9JTdCriapA/132',
        'nickName': '李四',
        'percent': '3%'
      },
      {
        "avatar": 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83epia5uwicw5nw1VhX9XCFHg0rRd6Bcy9VGczNDwyYEdTOL1C5fbFEu64PKrccdVNVHvCXx9JTdCriapA/132',
        'nickName': '王五',
        'percent': '4%'
      },
    ],
    is_over: true,
    is_show:false

  },
  /**
   * 弹出层函数
   */
  //出现
  show: function () {
    this.setData({ is_show: false })
  },
  //消失
  hide: function () {
    this.setData({ is_show: true })
  },
  getTimeData: function () {
    let that = this
    var data = {};
    var isData = true;
    var hours = '23';
    var minutes = '59';
    var seconds = '59';
    var percent = 5;

    var flag = setInterval(function () {
      seconds--;

      if (seconds < 0) {
        seconds = '59';
        if (minutes < 1) {
          minutes = '59';
          hours = (hours - 1).toString();
        } else {
          minutes = (minutes - 1).toString();
        }
      }

      // 添加前导0
      if (parseInt(hours) < 10 && hours.length < 2) {
        hours = '0' + hours;
      }

      if (parseInt(minutes) < 10 && minutes.length < 2) {
        minutes = '0' + minutes;
      }

      if (parseInt(seconds) < 10) {
        seconds = '0' + seconds;
      }

      // console.log(seconds);

      data.hours = hours;
      data.minutes = minutes;
      data.seconds = seconds;
      data.percent = percent++;

      if (parseInt(hours) <= 0 && parseInt(minutes) <= 0 && parseInt(seconds) <= 0) {
        that.setData({ is_over: false })
        clearInterval(flag);
      }

      data.isData = false;
      that.setData({ timeData: data });
      // $("#timeData").style('display','block');
    }, 1000);

    // this.data.timeData = data;
    // this.setData({ timeData: data });
    // console.log(this.data)
  },

  // 获取好友帮助
  getHelp: function () {
    wx.showShareMenu({
      withShareTicket: true,
    })
  },
  saveImg: function(){

    // wx.previewImage({
    //   current: '', // 当前显示图片的http链接
    //   urls: ['http://192.168.1.225/web/resource/minigrame/guangguang.jpg'] // 需要预览的图片http链接列表
    // })

    // wx.saveImageToPhotosAlbum({
    //   filePath: '../images/guangguang.jpg',
    //   success(res) {
    //     console.log(res)
    //   },
    //   fail(res) {
    //     console.log(res)
    //   }

    // })

    wx.getImageInfo({
      src: 'https://m-super.com/priceLift/images/guangguang.jpg',
      success: function (res) {
        console.log(res.width)
        console.log(res.height)
      }
    })


    // console.log('22222222')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ param: options.id })
    // console.log('111111')
    this.getTimeData();
    console.log(this.data.timeData)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // wx.showToast({
    //   'title':'该商品助力已结束！',
    //   'icon':'none',
    //   'duration':3000
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '邀您帮他加价助威，最高可使手机回收价翻一番！',
      path: '/pages/help/index?id=123'
    }
  },
})